clear all
set emptycells drop
set matsize 11000
set maxvar 32670

*Set working directory
if c(username)=="" { //insert username
cd "" // insert root path
}

if c(username)=="jonathancolmer" { 
	cd "/Users/jonathancolmer/The Lab Dropbox/Jonathan Colmer/ShotSpotter_env/Journal_submissions/ReStat/Replication Folder" 
}

if c(username)=="jmc4qg" { 
	cd "/Users/jmc4qg/The Lab Dropbox/Jonathan Colmer/ShotSpotter_env/Journal_submissions/ReStat/Replication Folder" 
}

use "Analysis Data/NIBRS_analysis.dta", clear

reghdfe homicide_pc tMean prec, absorb(ori_sample_month week dow) cluster(fips) keepsingletons
estimates save "Figures and Tables/Figure_A1/poly1.ster", replace

reghdfe homicide_pc tMean tMean2 prec, absorb(ori_sample_month week dow) cluster(fips) keepsingletons
estimates save "Figures and Tables/Figure_A1/poly2.ster", replace

reghdfe homicide_pc tMean tMean2 tMean3 prec, absorb(ori_sample_month week dow) cluster(fips) keepsingletons
estimates save "Figures and Tables/Figure_A1/poly3.ster", replace

reghdfe homicide_pc tMean tMean2 tMean3 tMean4 prec, absorb(ori_sample_month week dow) cluster(fips) keepsingletons
estimates save "Figures and Tables/Figure_A1/poly4.ster", replace


** Figure A1 a

clear all

set more off

local stackedgraphs

local temperatures 10 20 30

local lhsvar homicide_pc

local avg_t `temperature'

local starttemp -10

local endtemp 30

clear

local omit 11

set obs 41

gen temperature = 0.5

keep temperature

replace temperature = -10+_n-1

estimate use "Figures and Tables/Figure_A1/poly1.ster"


gen homicide_pc = .

predictnl yhat = temperature*(_b[tMean]) -(`omit'*(_b[tMean])), se(se) ci(lowerci upperci)
graph tw rarea upperci lowerci temperature if temperature >= `starttemp', fint(20) fcolor(black) alwidth(none) || line yhat temperature if temperature >= `starttemp', lcolor(black) yline(0) lcolor(black) xscale(range(`starttemp' `endtemp')) ylabel(-0.004(0.002)0.006,labsize(large)) xlabel(`starttemp'(10)`endtemp', labsize(large)) graphregion(fcolor(white)) xtitle("Daily Average Temperature", size(large)) ytitle("Change in the Number of Homicides" "per 100,000 people", size(large)) legend(off)
graph export "Figures and Tables/Figure_A1/Figure_A1a.png", replace


** Figure A1b

clear all

set more off

local stackedgraphs

local temperatures 10 20 30

local lhsvar homicide_pc

local avg_t `temperature'

local starttemp -10

local endtemp 30

clear

local omit 11

set obs 41

gen temperature = 0.5

keep temperature

replace temperature = -10+_n-1

estimate use "Figures and Tables/Figure_A1/poly2.ster"


gen homicide_pc = .

predictnl yhat = temperature*(_b[tMean])+temperature^2*(_b[tMean2]) -(`omit'*(_b[tMean])+`omit'^2*(_b[tMean2])), se(se) ci(lowerci upperci)
graph tw rarea upperci lowerci temperature if temperature >= `starttemp', fint(20) fcolor(black) alwidth(none) || line yhat temperature if temperature >= `starttemp', lcolor(black) yline(0) lcolor(black) xscale(range(`starttemp' `endtemp')) ylabel(-0.004(0.002)0.006,labsize(large)) xlabel(`starttemp'(10)`endtemp', labsize(large)) graphregion(fcolor(white)) xtitle("Daily Average Temperature", size(large)) ytitle("Change in the Number of Homicides" "per 100,000 people", size(large)) legend(off)
graph export "Figures and Tables/Figure_A1/Figure_A1b.png", replace


** Figure A1c

clear all

set more off

local stackedgraphs

local temperatures 10 20 30

local lhsvar homicide_pc

local avg_t `temperature'

local starttemp -10

local endtemp 30

clear

local omit 11

set obs 41

gen temperature = 0.5

keep temperature

replace temperature = -10+_n-1

estimate use "Figures and Tables/Figure_A1/poly3.ster"


gen homicide_pc = .

predictnl yhat = temperature*(_b[tMean])+temperature^2*(_b[tMean2])+temperature^3*(_b[tMean3]) -(`omit'*(_b[tMean])+`omit'^2*(_b[tMean2])+`omit'^3*(_b[tMean3])), se(se) ci(lowerci upperci)
graph tw rarea upperci lowerci temperature if temperature >= `starttemp', fint(20) fcolor(black) alwidth(none) || line yhat temperature if temperature >= `starttemp', lcolor(black) yline(0) lcolor(black) xscale(range(`starttemp' `endtemp')) ylabel(-0.004(0.002)0.006,labsize(large)) xlabel(`starttemp'(10)`endtemp', labsize(large)) graphregion(fcolor(white)) xtitle("Daily Average Temperature", size(large)) ytitle("Change in the Number of Homicides" "per 100,000 people", size(large)) legend(off)
graph export "Figures and Tables/Figure_A1/Figure_A1c.png", replace


** Figure A1d

clear all

set more off

local stackedgraphs

local temperatures 10 20 30

local lhsvar homicide_pc

local avg_t `temperature'

local starttemp -10

local endtemp 30

clear

local omit 11

set obs 41

gen temperature = 0.5

keep temperature

replace temperature = -10+_n-1

estimate use "Figures and Tables/Figure_A1/poly4.ster"


gen homicide_pc = .

predictnl yhat = temperature*(_b[tMean])+temperature^2*(_b[tMean2])+temperature^3*(_b[tMean3])+temperature^4*(_b[tMean4]) -(`omit'*(_b[tMean])+`omit'^2*(_b[tMean2])+`omit'^3*(_b[tMean3])+`omit'^4*(_b[tMean4])), se(se) ci(lowerci upperci)
graph tw rarea upperci lowerci temperature if temperature >= `starttemp', fint(20) fcolor(black) alwidth(none) || line yhat temperature if temperature >= `starttemp', lcolor(black) yline(0) lcolor(black) xscale(range(`starttemp' `endtemp')) ylabel(-0.004(0.002)0.006,labsize(large)) xlabel(`starttemp'(10)`endtemp', labsize(large)) graphregion(fcolor(white)) xtitle("Daily Average Temperature", size(large)) ytitle("Change in the Number of Homicides" "per 100,000 people", size(large)) legend(off)
graph export "Figures and Tables/Figure_A1/Figure_A1d.png", replace
